package com.example.my_flea_street.Mapper;

import com.example.my_flea_street.bean.Info;
import com.example.my_flea_street.bean.SearchUser;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface SearchMapper {
    @Select("select distinct key_word from information ORDER BY release_time desc LIMIT 10")
    List<String> getHotKeys();

    @Select("SELECT b.id ,b.release_time,b.text,b.pic,b.category,b.key_word,b.is_settled,b.is_banned,b.user_id,a.name,a.sex,a.head FROM user a,information b WHERE a.id=b.user_id and CONCAT(a.name,b.text,IFNULL(b.key_word,'')) like CONCAT('%',#{key},'%') ORDER BY release_time desc")
    Page<Info> searchInfo(@Param("key") String key);

    @Select("select id,head,name,introduction from user where concat(name,IFNULL(introduction,'')) like CONCAT('%',#{key},'%')")
    Page<SearchUser> searchUser(@Param("key") String key);
}
